{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cc30a19b",
   "metadata": {},
   "source": [
    "[参考博客](https://copyfuture.com/blogs-details/202204141348108775)\n",
    "\n",
    "\n",
    "# 原则六：里氏替换原则（Liskov Substitution Principle\n",
    "\n",
    "## 定义\n",
    "In a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e. an object of type T may be substituted with any object of a subtype S) without altering any of the desirable properties of the program (correctness, task performed, etc.)\n",
    "\n",
    "\n",
    "即：所有引用基类的地方必须能透明地使用其子类的对象，也就是说子类对象可以替换其父类对象，而程序执行效果不变。\n",
    "\n",
    "## 定义的解读\n",
    "在继承体系中，子类中可以增加自己特有的方法，也可以实现父类的抽象方法，但是不能重写父类的非抽象方法，否则该继承关系就不是一个正确的继承关系。\n",
    "\n",
    "## 优点\n",
    "可以检验继承使用的正确性，约束继承在使用上的泛滥。\n",
    "\n",
    "## 代码讲解\n",
    "在这里用一个简单的长方形与正方形的例子讲解一下里氏替换原则。\n",
    "\n",
    "### 需求点\n",
    "\n",
    "创建两个类：长方形和正方形，都可以设置宽高（边长），也可以输出面积大小。\n",
    "\n",
    "### 不好的设计\n",
    "\n",
    "首先声明一个长方形类，然后让正方形类继承于长方形。\n",
    "\n",
    "长方形类："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45a7cc66",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9730d795",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "849c5549",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a3e3ad5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e695daf1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee9b2028",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d490361",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2754a8bb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eda5e44b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ab7b1bf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
